﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using ZilLion.Service.Core.Domain.EntityBase.JsonConverter;

namespace ZilLion.Service.WeChatMall.Domain.Entitys.Orders
{
    public class OrderCompletedInfoDto
    {
        [JsonProperty("main")]
        public OrderMainInfoEntity MainInfo { get; set; }

        [JsonProperty("sinceinfo")]
        public OrderDeliverySinceDto SinceInfo { get; set; }

        [JsonProperty("sendinfo")]
        public OrderDeliverySendDto SendInfo { get; set; }

        [JsonProperty("detaillist")]
        public IList<OrderDetailDto> DetailInfos { get; set; }
    }


    /// <summary>
    ///     订单摘要(订单历史也用)
    /// </summary>
    public class OrderAbstractDto
    {
        public OrderAbstractDto()
        {
        }

        public OrderAbstractDto(OrderCompletedInfoDto completedInfoDto)
        {
            Shopname = completedInfoDto.MainInfo.Shopname;
            DealMy = completedInfoDto.MainInfo.DealMy + completedInfoDto.MainInfo.FeeMy;
            Sno = completedInfoDto.MainInfo.Sno;
            ShopId = completedInfoDto.MainInfo.Shopid;
            BillDate = completedInfoDto.MainInfo.Billdate;
            var count = completedInfoDto.DetailInfos.Count;
            var abstractinfo = completedInfoDto.DetailInfos.FirstOrDefault()?.Gsname;
            DetailAbstract = count > 1 ? $"{abstractinfo}  等 共 {count} 项" : $"{abstractinfo} 共 {count} 项";
        }

        /// <summary>
        ///     订单店铺
        /// </summary>
        [JsonProperty("shopname")]
        public string Shopname { get; set; }

        /// <summary>
        ///     店铺ID
        /// </summary>
        [JsonProperty("shopid")]
        public long ShopId { get; set; }

        /// <summary>
        ///     订单成交价
        /// </summary>
        [JsonProperty("dealmy")]
        public decimal DealMy { get; set; }

        /// <summary>
        ///     流水号
        /// </summary>
        [JsonProperty("sno")]
        public string Sno { get; set; }

        /// <summary>
        ///     单据日期
        /// </summary>
        [JsonProperty("billdate")]
        [JsonConverter(typeof(ChinaDateTimeConverter))]
        public DateTime BillDate { get; set; }

        /// <summary>
        ///     明细摘要  如 xxxx货品等 共1项
        /// </summary>
        [JsonProperty("detailabstract")]
        public string DetailAbstract { get; set; }
    }
}